package beanstao.util.type.base;

import java.lang.reflect.Array;
import java.util.Collection;

import beanstao.util.exception.technical.util.reflect.FailToCastObjectException;
import beanstao.util.type.Castor;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class Array2Collection extends Castor<Object, Collection>
{

	public Array2Collection()
	{
		fromClass = Array.class;
		toClass = Collection.class;
	}

	@Override
	public Collection<?> cast(Object src, Class<?> toType, String... args) throws FailToCastObjectException
	{
		Collection coll = createCollection(src, toType);
		for (int i = 0; i < Array.getLength(src); i++)
			coll.add(Array.get(src, i));
		return coll;

	}
}
